﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BonsaiScrum.Core.Domain.Shared
{
    public abstract class BaseEntity<T> : IIdentifiable<int>, IEquatable<T>
        where T : class, IIdentifiable<int>
    {
        public virtual int Id { get; private set; }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, null)) return false;
            if (ReferenceEquals(obj, this)) return true;
            if (obj.GetType() != typeof(T)) return false;

            return Equals((T)obj);
        }

        public override int GetHashCode()
        {
            return typeof(T).GetHashCode() ^ Id;
        }

        public virtual bool Equals(T other)
        {
            if (ReferenceEquals(other, null)) return false;
            if (ReferenceEquals(other, this)) return true;
            return this.Id.Equals(other.Id);
        }

        public virtual bool IsTransient()
        {
            return Id.Equals(default(int));
        }
    }
}
